package com.popo.test;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class GetJar {
	public static void main(String[] args) {
		try {
			File f = new File("aa.jar");
			FileInputStream fis = new FileInputStream(f);
		    long l =f.length();
			DataInputStream fin = new  DataInputStream( new FileInputStream(f));
			DataOutputStream fout = new DataOutputStream( new FileOutputStream("./aa_1.jar"));
			
			boolean read =false;
			byte b1=0;
			byte b2=0;
			byte b3=0;
			try {
				while(l>0){
					byte b=fin.readByte();
					
					if(b==0x50){
						b1=b;
					}
					
					if(b==0x4B && b1==0x50){
						read =true;
						
						b2=(byte) 0xFE;
						b3=(byte) 0xFE;
						fout.write(new byte[]{b1});
						b1=(byte) 0xFE;
					}
					
					if(read==true){
						fout.write(new byte[]{b});
					}
					
					if(b==0x00 && b1!=0x00){
						System.out.println("b1=0x00");
						b1=0x00;
					}else if(b== 0x00 &&   b1==0x00 && b2!=0x00){
						System.out.println("b2=0x00");
						b2=0x00;
					}else if(b==0x00 && b1 ==0x00 && b2==0x00){
						System.out.println("b3=0x00");
						fin.close();
						fout.close();
						System.exit(1);
						return ;
						
					}else if(b1==0x00){
						b1=0x22;
					}
					
					
					l--;
				}
				
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
}
